package com.yusvn.scm.goods.base.controller;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.yusvn.scm.common.BaseController;
import com.yusvn.scm.common.kit.MyKit;
import com.yusvn.scm.common.kit.RetKit;
import com.yusvn.scm.goods.base.service.ScmBhspService;

public class ScmBhspController extends BaseController {


     @Inject
     ScmBhspService srv;

    /**
     * 查询不补商品
     */
    public void page(){
        // 获取当前登录用户
        Kv  kv= getKv();
        kv.set("userid", getLoginUserId());
        kv.set("userCode", getLoginErpUsercode());

        Page<Record> list = srv.selectPzbhList(kv);

        renderJson(RetKit.ok().setCount(list.getTotalRow()).setData( JSONObject.toJSON(list.getList()) ));
    }


    /**
     * 单条修改不补状态
     */
    public void updateZt(){
        Kv kv = MyKit.jsonStrToKv(getRawData(), true);
        if (kv.isEmpty()) {
            kv = getKv();
        }
        kv.set("userid", getLoginUserId());
        kv.set("userCode", getLoginErpUsercode());
        renderJson(srv.updateZt(kv));
    }

    /**
     * 启用或停用筛选修改状态
     */
    public void qySxsp(){
        Kv kv = MyKit.jsonStrToKv(getRawData(), true);
        if (kv.isEmpty()) {
            kv = getKv();
        }
        kv.set("userid", getLoginUserId());
        kv.set("userCode", getLoginErpUsercode());
        renderJson(srv.qySxsp(kv));
    }


    /**
     * 启用或停用勾选项
     */
    public void qyGxsp(){
        Kv kv = MyKit.jsonStrToKv(getRawData(), true);
        if (kv.isEmpty()) {
            kv = getKv();
        }
        kv.set("userid", getLoginUserId());
        kv.set("userCode", getLoginErpUsercode());
        renderJson(srv.qyGxsp(kv));
    }


    public void tyQbsp(){
        Kv kv = MyKit.jsonStrToKv(getRawData(), true);
        if (kv.isEmpty()) {
            kv = getKv();
        }
        kv.set("userid", getLoginUserId());
        kv.set("userCode", getLoginErpUsercode());
        renderJson(srv.tyQbsp(kv));
    }
}
